
var lkssChart;
var returnLkssData = [];

var lkssObj = new Vue({
	el: '#lkssTab',
	data: {
		year: '',
		isAll: false,
		zsList:{
			yslk: true
			/*xbkc: false
			xbjtc: false,
			dbggc: false*/
		},
		tbList: {
			yslktb: true
			/*xbkctb: false
			xbjtctb: false,
			dbggctb: false*/
		},
		hbList: {
			yslkhb: true
			/*xbkchb: false
			xbjtchb: false,
			dbggchb: false*/
		}
	},
	created: function(){


	},
	watch:{
		"zsList.yslk":function(val, oldVal){	//运输旅客
    		lkssChart.setOption(subStrOptionLkss(returnLkssData),true)
		},"tbList.yslktb":function(val, oldVal){	//运输旅客同比
    		lkssChart.setOption(subStrOptionLkss(returnLkssData),true)
		}
		/*,"hbList.yslkhb":function(val, oldVal){	//运输旅客环比
    		lkssChart.setOption(subStrOptionLkss(returnLkssData),true)
		}
		,
		"zsList.xbkc":function(val, oldVal){	//西部客船
    		lkssChart.setOption(subStrOptionLkss(returnLkssData),true)
		},
		"zsList.xbjtc":function(val, oldVal){	//西部交通船
    		lkssChart.setOption(subStrOptionLkss(returnLkssData),true)
		},
		"zsList.dbggc":function(val, oldVal){	//东部观光船
    		lkssChart.setOption(subStrOptionLkss(returnLkssData),true)
		},
		
		"tbList.xbkctb":function(val, oldVal){	//西部客船同比
    		lkssChart.setOption(subStrOptionLkss(returnLkssData),true)
		},
		/*"tbList.xbjtctb":function(val, oldVal){	//西部交通船同比
    		lkssChart.setOption(subStrOptionLkss(returnLkssData),true)
		},
		"tbList.dbggctb":function(val, oldVal){	//东部观光船同比
    		lkssChart.setOption(subStrOptionLkss(returnLkssData),true)
		},
		"hbList.yslkhb":function(val, oldVal){	//运输旅客环比
    		lkssChart.setOption(subStrOptionLkss(returnLkssData),true)
		},
		"hbList.xbkchb":function(val, oldVal){	//西部客船环比
    		lkssChart.setOption(subStrOptionLkss(returnLkssData),true)
		}/*,
		"hbList.xbjtchb":function(val, oldVal){	//西部交通船环比
    		lkssChart.setOption(subStrOptionLkss(returnLkssData),true)
		},
		"hbList.dbggchb":function(val, oldVal){	//东部观光船环比
    		lkssChart.setOption(subStrOptionLkss(returnLkssData),true)
		},*/
	},
	methods:{
		checkAll: function(){
			this.zsList.yslk = this.isAll;
			/*this.zsList.xbkc　= this.isAll;
			this.zsList.xbjtc　= this.isAll;
			this.zsList.dbggc　= this.isAll;*/
			
			this.tbList.yslktb　= this.isAll;
			/*this.tbList.xbkctb　= this.isAll;
			this.tbList.xbjtctb　= this.isAll;
			this.tbList.dbggctb　= this.isAll;*/
			
			//this.hbList.yslkhb　= this.isAll;
			/*this.hbList.xbkchb　= this.isAll;
			this.hbList.xbjtchb　= this.isAll;
			this.hbList.dbggchb　= this.isAll;*/

    		lkssChart.setOption(subStrOptionLkss(returnLkssData),true)
		}
	}
})

/*当页面非默认当前分类的柱状图时，需要把下面的初始化代码注释，不然加载的图会变形*/
/*$(function(){
	lkssObj.year =new Date().getFullYear();
	bindLkssData();
})*/

function searchOrTimelkss(){
	if($('#timelkss').val()==""){
		lkssObj.year =new Date().getFullYear();
	}
	else{
		lkssObj.year =$('#timelkss').val();}
	$.ajax({ 
		type: "POST",
		url: "/tszt/findsjfb.jspx", 
		data: {channelIds: 366, year: lkssObj.year, orderBy: 36},
		success: function(data){
			if(data.code == 200){
				if(data.body.length == 0){
					lkssObj.year = new Date().getFullYear() - 1;
					bindLkssData();
				}
				returnLkssData = data.body;
			}

			bindLkss(returnLkssData);//运输旅客总数初始化
      	}
	});
}

function bindLkssData(){
	if(returnLkssData.length == 0){
		
		$.ajax({ 
			type: "POST",
			url: "/tszt/findsjfb.jspx", 
			data: {channelIds: 366, year: lkssObj.year, orderBy: 36},
			success: function(data){
				if(data.code == 200){
					if(data.body.length == 0){
						lkssObj.year = new Date().getFullYear() - 1;
						bindLkssData();
					}
					returnLkssData = data.body;
				}
	
				bindLkss(returnLkssData);//运输旅客总数初始化
	      	}
		});
	}
}

function subStrLegendLkss(){
	var legend = [];

	if(lkssObj.zsList.yslk)
		legend.push('运输旅客总数');
    /*if(lkssObj.zsList.xbkc)
		legend.push('客船');
    if(lkssObj.zsList.xbjtc)
		legend.push('西部交通船');
    if(lkssObj.zsList.dbggc)
		legend.push('东部观光船');*/
	return legend;
}

function subStrXAxisLkss(returnLkssData){
	var xAxis = [];
	if(returnLkssData.length<12){
		xAxis=['1月份','2月份','3月份','4月份','5月份','6月份','7月份','8月份','9月份','10月份','11月份','12月份'];
	}
	else{
	returnLkssData.forEach(function(month){ 
		xAxis.push(month.attr_month + '月份');
	}); 
	}
	return xAxis;
}


function subStrSeriesLkss(returnLkssData){
	var series = [];

	var lkssData = [];
	var lkssDataTb = [];
	var lkssDataHb = [];

	/*var ckxbkcData = [];
	var ckxbkcDataTb = [];
	var ckxbkcDataHb = [];

	var ckxbjtcData = [];
	var ckxbjtcDataTb = [];
	var ckxbjtcDataHb = [];

	var ckdbggcData = [];
	var ckdbggcDataTb = [];
	var ckdbggcDataHb = [];*/


	returnLkssData.forEach(function(val){ 
		//运输旅客总数
		lkssData.push(val.attr_yslk); //总数
		lkssDataTb.push(val.attr_yslktb);	//同比
		//lkssDataHb.push(val.attr_yslkhb);//环比
		//西部客船
		/*ckxbkcData.push(val.attr_xbkc); //总数
		ckxbkcDataTb.push(val.attr_xbkctb);	//同比
		ckxbkcDataHb.push(val.attr_xbkchb);//环比
		//西部交通船
		ckxbjtcData.push(val.attr_xbjtc); //总数
		ckxbjtcDataTb.push(val.attr_xbjtctb);	//同比
		ckxbjtcDataHb.push(val.attr_xbjtchb);//环比
		//东部观光船
		ckdbggcData.push(val.attr_dbggc); //总数
		ckdbggcDataTb.push(val.attr_dbggctb);	//同比
		ckdbggcDataHb.push(val.attr_dbggchb);//环比
*/	}); 
	

	if(lkssObj.zsList.yslk){	//运输旅客总数
	    var d = 
		{
            name: '客船运载旅客总数',
            type: 'bar',
            itemStyle: {
                normal: {
					color: "#00CCFF",
                    label: {
                    	show: true,
                        position: 'top',
                        formatter: '{c}'
                    }
                }
            },
            data: lkssData
        };
	    series.push(d);
	}

	if(lkssObj.tbList.yslktb){	//运输旅客同比
		var d = 
      	{
             name: '运输旅客总数同比',
             type: 'line',
             yAxisIndex: 1,
             itemStyle: {
                 normal: {
					 color: "#CC66FF",
                     label: {
                         show: true,
                         position: 'top',
                         formatter: '{c}%'
                     }
                 }
             },
             data: lkssDataTb
        };

	    series.push(d);
	}


	if(lkssObj.hbList.yslkhb){	//运输旅客环比
		var d = 
      	{
             name: '运输旅客总数环比',
             type: 'scatter',
             yAxisIndex: 1,
             itemStyle: {
                 normal: {
						color: "#FF9900",
                     label: {
                         show: true,
                         position: 'top',
                         formatter: '{c}%'
                     }
                 }
             },
             data: lkssDataHb
        };

	    series.push(d);
	}


	/*if(lkssObj.zsList.xbkc){	//西部客船
	    var d = 
		{
            name: '客船',
            type: 'bar',
            itemStyle: {
                normal: {
					color: "#5cb85c",
                    label: {
                    	show: true,
                        position: 'top',
                        formatter: '{c}'
                    }
                }
            },
            data: ckxbkcData
        };
	    series.push(d);
	}

	if(lkssObj.tbList.xbkctb){	//西部客船同比
		var d = 
      	{
             name: '客船同比',
             type: 'line',
             yAxisIndex: 1,
             itemStyle: {
                 normal: {
						color: "#5cb85c",
                     label: {
                         show: true,
                         position: 'top',
                         formatter: '{c}%'
                     }
                 }
             },
             data: ckxbkcDataTb
        };

	    series.push(d);
	}


	if(lkssObj.hbList.xbkchb){	//西部客船环比
		var d = 
      	{
             name: '客船环比',
             type: 'scatter',
             yAxisIndex: 1,
             itemStyle: {
                 normal: {
						color: "#5cb85c",
                     label: {
                         show: true,
                         position: 'top',
                         formatter: '{c}%'
                     }
                 }
             },
             data: ckxbkcDataHb
        };

	    series.push(d);
	}

	if(lkssObj.zsList.xbjtc){	//西部交通船
	    var d = 
		{
            name: '西部交通船',
            type: 'bar',
            itemStyle: {
                normal: {
					color: "#0078c1",
                    label: {
                    	show: true,
                        position: 'top',
                        formatter: '{c}'
                    }
                }
            },
            data: ckxbjtcData
        };
	    series.push(d);
	}

	if(lkssObj.tbList.xbjtctb){	//西部交通船同比
		var d = 
      	{
             name: '西部交通船同比',
             type: 'line',
             yAxisIndex: 1,
             itemStyle: {
                 normal: {
						color: "#0078c1",
                     label: {
                         show: true,
                         position: 'top',
                         formatter: '{c}%'
                     }
                 }
             },
             data: ckxbjtcDataTb
        };

	    series.push(d);
	}


	if(lkssObj.hbList.xbjtchb){	//西部交通船环比
		var d = 
      	{
             name: '西部交通船环比',
             type: 'scatter',
             yAxisIndex: 1,
             itemStyle: {
                 normal: {
						color: "#0078c1",
                     label: {
                         show: true,
                         position: 'top',
                         formatter: '{c}%'
                     }
                 }
             },
             data: ckxbjtcDataHb
        };

	    series.push(d);
	}

	if(lkssObj.zsList.dbggc){	//东部观光船
	    var d = 
		{
            name: '东部观光船',
            type: 'bar',
            itemStyle: {
                normal: {
					color: "#f0ad4e",
                    label: {
                    	show: true,
                        position: 'top',
                        formatter: '{c}'
                    }
                }
            },
            data: ckdbggcData
        };
	    series.push(d);
	}

	if(lkssObj.tbList.dbggctb){	//东部观光船同比
		var d = 
      	{
             name: '东部观光船同比',
             type: 'line',
             yAxisIndex: 1,
             itemStyle: {
                 normal: {
						color: "#f0ad4e",
                     label: {
                         show: true,
                         position: 'top',
                         formatter: '{c}%'
                     }
                 }
             },
             data: ckdbggcDataTb
        };

	    series.push(d);
	}


	if(lkssObj.hbList.dbggchb){	//东部观光船环比
		var d = 
      	{
             name: '东部观光船环比',
             type: 'scatter',
             yAxisIndex: 1,
             itemStyle: {
                 normal: {
						color: "#f0ad4e",
                     label: {
                         show: true,
                         position: 'top',
                         formatter: '{c}%'
                     }
                 }
             },
             data: ckdbggcDataHb
        };

	    series.push(d);
	}
*/
	return series;
}

function subStrOptionLkss(){

	var legendData = subStrLegendLkss();
	var xAxisData = subStrXAxisLkss(returnLkssData);
	var seriesData = subStrSeriesLkss(returnLkssData);

    var option = {
    		toolbox: {
  			　　show: true,
  			   right: 20,     			  
  			　　feature: {
  			　　　　saveAsImage: {
  			　　　　show:true,
  			　　　　excludeComponents :['toolbox'],
  			　　　　pixelRatio: 2,
  			  itemStyle: {
  	                color: '#254065'
  	            }
  			　　　　}
  			　　}
  			},
    		title: {
    			text: lkssObj.year + '年'
    		},	
    		
    		 tooltip: {
              	trigger: 'axis',
              	 axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                      type: 'line'        //指示器类型。
                  },
                  formatter: function (params) {//提示框自定义
                      return formatterTip(params);
                  },
                 
     		 },

            legend: {
                data: legendData,
                textStyle: {
                    color: '#A7A7A7',
                },
            },
          
            xAxis: {
                data: xAxisData
            },

            yAxis: [
            	{
                    type: 'value',
                    name: '总数'
                },
                {
                    type: 'value',
                    axisLabel: {
                        show: true,
                        interval: 'auto',
                        formatter: '{value}%'
                    },
                    name: '百分比%'
                }
            ],
        
           series: seriesData
		};
    
    
    return option;
}


//运输旅客总数图表初始化
function bindLkss(returnLkssData){

	lkssChart = echarts.init(document.getElementById('chartLkss'));

    var option = subStrOptionLkss(returnLkssData);
	
    // 使用刚指定的配置项和数据显示图表。
    lkssChart.setOption(option);
}